package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("showuser")
    public String toUser(Model model, @RequestParam("id") Long id) {
        User user = userService.findUserById(id);
        model.addAttribute("user", user);
        return "user";
    }

    @RequestMapping("deleteuser")
    public String deleteUserById(@RequestParam("id") Long id, Model model) {
        userService.deleteUserById(id);
        return "user";
    }
}
